package com.yao.exception;

import com.yao.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobaExceptionHandler {

    /**
     * 全局异常处理
     * @param exception
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result globaException(Exception exception){
        exception.printStackTrace();
        return Result.error(StringUtils.hasLength(exception.getMessage())? exception.getMessage(): "出现未知异常，请联系管理员");
    }
}
